package com.zzp.baidu.config;

import com.zzp.baidu.export.NewsExport;
import com.zzp.baidu.mapper.NewsMapper;
import javax.annotation.Resource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;

/**
 * 开启时批量插入新闻
 * <p>
 *  //TODO
 *  BatchConfig.java
 * </p>
 * @version v0.0.1
 * @author 佐斯特勒
 * @date 2021/2/14 21:42
 * @see  com.zzp.baidu.config
 **/
@Configuration
public class BatchConfig {
    @Resource
    private ElasticsearchRestTemplate elasticsearchRestTemplate;

    @Resource
    private NewsMapper newsMapper;

    /**
     * 迭代次数
     */
    private final static int STEP = 10;

    /**
     * 初始化并开始批量插入
     * @return .
     */
    @Bean(initMethod = "initInsert")
    public NewsExport esBatchInsert(){
        return new NewsExport(elasticsearchRestTemplate, newsMapper).setStep(STEP);
    }
}
